package com.qfjy.project.threadPools;

import com.qfjy.project.weixin.api.message.CustomMessageUtil;
import com.qfjy.project.weixin.util.MailUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


@Service
@Slf4j
public class MessageThread {

    private final ExecutorService executorService;
    @Resource
    private MailUtils mailUtils;
    @Resource
    private CustomMessageUtil customMessageUtil;

    public MessageThread() {
        executorService = Executors.newFixedThreadPool(10);
    }

    /**
     * 发送邮件
     *
     * @param email
     * @param msg
     */
    public void sendEmail(String email, String msg) {
        executorService.submit(() -> {
            mailUtils.sendSimpleMail(email, "绑定成功", msg);
        });
    }

    /**
     * 发送短信
     *
     * @param phoneNumber
     */
    public void sendSMS(String phoneNumber) {
        executorService.submit(() -> {
            log.info("短信----->" + phoneNumber);
        });
    }

    /**
     * 发送微信消息
     *
     * @param openid
     * @param content
     */
    public void sendWeChatMessage(String openid, String content) {
        executorService.submit(() -> {
            customMessageUtil.sendMessageText(openid, content);
        });
    }

    public void shutdown() {
        // 关闭线程池
        executorService.shutdown();
    }

}
